/*
Author : Nguyen Van Ty
Email  : ngvanty03@gmail.com
Date   : 12/11/2010 

*/

using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Utility;
using BusinessObject;
using System.Xml;

namespace DataAccessLayer
{
    /// <summary>
    /// Define CategoryDao class. This class inherit from  CategoryDaoBase class.
    /// If you want add new function, you must define here.
    /// </summary>
    public class CategoryDao : CategoryDaoBase
    {
        private static ILog logger = null;
        #region Constructor
        /// <summary>
        /// Define Constructor.
        /// </summary>
        public CategoryDao() { }
        static CategoryDao()
        {
            // Init logger.
            logger = LoggingUtility.GetLogger(typeof(CategoryDao).FullName);
        }
        public static List<CategoryResult> GetAllCategoryToControl()
        {
            String methodName = "SearchCategorySomeCondition";
            if (logger.IsDebugEnabled)
            {
                LoggingUtility.logMethodEntry(logger, methodName);
            }

            try
            {
                List<CategoryResult> listCategory = new List<CategoryResult>();
                DbCommand cmd = ManagerDao.GetStoredProcCommand("spGetAllCategoryToControl");                
                using (IDataReader reader = ManagerDao.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        listCategory.Add(GetCategoryResultByDataReader(reader));
                        
                    }

                    reader.Close();
                }

                return listCategory;
            }
            catch (Exception ex)
            {
                //write error message to log file.
                logger.Error(methodName, ex);
                return null;
            }
        }
    }
}
        #endregion